Most object-oriented languages have some form of switch statement that allows the value of data to influence the control flow of a program. The following is an example switch statement in a Visual Basic program:
Dim N As Integer. . .Select N  Case 1 To 5    . . . statement executed when N is 1, 2, 3, 4, or 5 . . .  Case 6, 7, 8    . . . statement executed when N is 6, 7, or 8 . . .  Case Else    . . . default branchEnd Select
As illustrated above, the values in the branches of the switch statement are usually limited to types that have numbers, Booleans, and/or strings as literals. Thus, in most object-oriented languages, such as Visual Basic, for example, only simple (i.e., non-structured) types may have literals.
Functional languages, such as Haskell and Service Modeling Language (SML), generalize such switch statements by using pattern matching as a convenient notation to bind variables based on the structure of incoming data. This is possible because functional languages typically support literals for structured types, such as lists, trees, and the like. For example, the statement below performs a pattern match on the argument list xs, checking to determine whether it is either empty [ ], or of the form y:ys, in which case it binds y to the head (hd xs) of the list and ys to the tail (tl xs) of the list:
length::[a]−>Int                length xs=                    case xs of                            [ ]−>0                (y:ys)−>1+length ys                                                
In this example, the values have structure. Accordingly, instead of switching only on constants (i.e., non-structured types), switching may also occur on structured values. In addition, substructures may also be bound to variables. By contrast, where pattern matching is performed on non-structured type literals, there is nothing to bind. A variable may be bound when the variable is given a value. Thus, a variable may have a name, type, and, if bound, a value.
The expressiveness of pattern matching may be derived from the fact that the compiler may perform extensive rewriting on the source code to extract the matched values, binding them to the indicated variables, while maintaining the correct branching control structure. With the introduction of structured literals (e.g., XML literals, object literals, type literals, etc.) into various object-oriented and functional programming languages, it would be desirable to use structured literals to implement pattern matching in these programming languages.